package com.web.employees;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.Employees;
import com.service.EmployeesService;
import com.util.AuthenticateHttpServlet;
import com.util.MD5Util;

/**
 * Servlet implementation class ProductHandler
 */
@WebServlet("/Employee/Create")
public class EmployeeCreate extends AuthenticateHttpServlet {
	private static final long serialVersionUID = 1L;

	protected void post(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			String code = request.getParameter("code");
			String username = request.getParameter("username");
			String lastName = request.getParameter("lastName");
			String firstName = request.getParameter("firstName");
			String password = MD5Util.md5(request.getParameter("username")
					+ request.getParameter("passwd"));
			String extension = request.getParameter("extension");
			String email = request.getParameter("email");
			EmployeesService service = new EmployeesService();
			service.insert(new Employees(code, username, lastName, firstName,
					password, extension, email));
			request.getRequestDispatcher("../Employee/List").forward(request,
					response);
		} catch (NumberFormatException ex) {
			ex.printStackTrace();
		}
	}
}
